package com.amigo.online.provider.sync.handle.service.impl;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSONObject;
import com.amigo.online.provider.common.RedisKey;
import com.amigo.online.provider.sync.handle.data.redis.service.MusicRedisService;
import com.amigo.online.provider.sync.handle.service.AbstractDataHandler;
import com.amigo.online.provider.sync.handle.service.DataHandler;

@Service("musicRedisDataHandler")
@SuppressWarnings({"rawtypes", "unchecked"})
public class MusicRedisDataHandler extends AbstractDataHandler implements DataHandler {

    @Autowired
    @Qualifier("userRedisTemplate")
    RedisTemplate videoRedisTemplate;

    private static List<String> MUSIC_UPDATE_COL;

    @Value("${redis_video_update_col}")
    public void setMusicUpdateCol(String musicUpdateCol) {
        MUSIC_UPDATE_COL = Arrays.asList(musicUpdateCol.split(","));
    }

    @Autowired
    MusicRedisService musicRedisService;

    @Override
    public void updateHandle(JSONObject newObject, JSONObject oldObjecet) {
        long id = newObject.getLongValue("id");
        for (String temp : oldObjecet.keySet()) {
            if (MUSIC_UPDATE_COL.contains(temp)) {
                videoRedisTemplate.delete(RedisKey.MUSIC_REDIS_KEY + id);
                break;
            }
        }

    }

    @Override
    public void insertHandle(JSONObject newObject) {

    }

    @Override
    public void updateInfoByIdThroughHashMap(Long id, Map updateMap) {
        //  Auto-generated method stub

    }

    @Override
    public void insertObject(Object source) {
        //  Auto-generated method stub

    }

}
